const http = require("http");
const url = require("url");
const fs = require("fs");
const qs = require("querystring");

const server = http.createServer((req, res) => {
  let urlObj = url.parse(req.url, true);
  console.log("1",urlObj)
  let pathname = urlObj.pathname;
  if (pathname == "/") {
    let data = fs.readFileSync("./views/index.html");
    res.write(data);
    res.end();
  } else if (pathname == "/postdata") {
    let str = "";
    req.on("data", (chunk) => {
      str += chunk;
    });
    req.on("end", () => {
      console.log(str);
      let resObj = qs.parse(str);
      console.log('2',resObj);
    });
    res.write("返回post的数据");
    res.end();
  }
});
server.listen(9090);
